fix(hooks): use SessionEnd not Stop for Claude Code transcript extraction#355
Conversation
…tion
The Claude Code adapter installs the `stop.py` extraction hook on the
`Stop` event, which fires per assistant turn (once per response). The
intent — per the README and stop.py docstring — is session-end
extraction. The Gemini adapter at adapters/gemini.py:27 already uses
`SessionEnd` correctly; the Claude adapter was missed.
Per Claude Code docs (code.claude.com/docs/en/hooks):
- `Stop` fires once per turn ("when Claude finishes responding")
- `SessionEnd` fires once per session ("when a session terminates")
Net effect of the bug: every assistant turn triggers an ingest spawn.
The 20/hr budget + 2-process spawn cap prevent runaway, but produces
~1 ingest spawn every ~10s on chatty sessions — most then no-op via
the size-dedup gate but still cost the python.exe spawn cycle.
Fix is the trivial event-name swap on the Claude adapter only.
Codex (adapters/codex.py:30) and Kimi (adapters/kimi.py:30) adapters
intentionally untouched — they correctly use 'Stop' per their own
CLI specs.
Files changed:
- truememory/ingest/cli.py:794 docstring narrative
- truememory/ingest/cli.py:812 installer event key (the bug)
- truememory/ingest/cli.py:1086 expected-events health check
- truememory/ingest/CLAUDE_TEMPLATE.md user-facing narrative
- docs/architecture.md
- install.sh comment
Co-Authored-By: claude-opus-4-7 <wontreply@getfucked.ai>
|
Closing — current per-turn Stop hook with should_extract_session() size check + budget cap is better design than once-at-session-end. Incremental extraction gives memories mid-conversation. |
|
@buildingjoshbetter I understand what you are saying, but you already have that covered with User Prompt Submit. What I'm proposing is three hooks:
Previously, you were using "Stop" instead of "SessionEnd" - that works for codex but not for Claude Code Hook syntax. If you use both a "Stop" hook and a "UserPromptSubmit" it fires TWICE - once when the user types a prompt, once when claude sends it's final response. - Which is the setup you have now. I don't see any setup where you inject context into the chat based on the user's prompt, other than the stop hook, but that injects it too late, obviously, because it's after the Claude response. I sort of understand what you're getting at, though, but it seems to me that you could simply save memories every time the user submits a prompt, as well as inject any relevant memories, instead of using two hooks. |
Summary
The Claude Code adapter wires
stop.pyto the per-turnStopevent instead of the per-sessionSessionEndevent. Per Claude Code's hook docs:Stopfires once per assistant response;SessionEndfires once per session terminate. Result: every turn triggers an ingest spawn — the 20/hr budget + 2-process spawn cap prevent runaway, but produces visible ingest spam on chatty sessions, most of which then no-op via the size-dedup gate but still pay thepython.exespawn cost.The Gemini adapter at
truememory/hooks/adapters/gemini.py:27already usesSessionEndcorrectly — this brings the Claude adapter in line with that pattern. Codex (adapters/codex.py:30) and Kimi (adapters/kimi.py:30) intentionally untouched — they correctly useStopper their own CLI specs.Changes
truememory/ingest/cli.py:794truememory/ingest/cli.py:812"Stop"→"SessionEnd"(the bug)truememory/ingest/cli.py:1086truememory/ingest/CLAUDE_TEMPLATE.md:36docs/architecture.md:43install.sh:15Test plan
truememory-ingest statusshowsHooks installed: SessionStart, UserPromptSubmit, SessionEnd, PreCompact~/.claude/settings.jsoncontains a"SessionEnd"block pointing atstop.pyps -ef | grep truememory.ingest.clireturns nothing during the conversation)Stopper their CLI specs)References
truememory/hooks/adapters/gemini.py:27Co-Authored-By: claude-opus-4-7 wontreply@getfucked.ai